home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / business / stata3 / tables.tut < prev    next >
Encoding:
Text File  |  1988-08-29  |  6.5 KB  |  203 lines

  1. set output error
  2. set display page 23
  3. set more 1
  4. #delimit ;
  5.  
  6. di _n(5) in wh
  7. "  ___  ____  ____  ____  ____ tm" _n
  8. " /__    /   ____/   /   ____/" _n
  9. "___/   /   /___/   /   /___/    How to Make Tables" _n
  10. "--------------------------------------------------" _n(2) ;
  11.  
  12. di in gr
  13. "This tutorial explores Stata's ability to make tables of counts and summary" _n
  14. "statistics.  All are provided by the '"
  15. in wh "tabulate" in gr "' command." _n(2)
  16. "We will be using data on 58 patients, each of whom suffered from one of three"
  17. _n
  18. "diseases and each of whom was administered one of four drugs.  Recorded along"
  19. _n
  20. "with the disease and drug was the change in the patients' systolic blood pres-"
  21. _n
  22. "sure." _n(8) ;
  23.  
  24. #delimit cr
  25. mac def path
  26. capture run nullfile.tut
  27. if _rc {
  28.     mac def path "\stata\"
  29.     capture run %path`nullfile.tut
  30.     if _rc {
  31.         mac def path "/usr/stata/"
  32.         capture run %path`nullfile.tut
  33.         if _rc {
  34.             #delimit ;
  35.             di in red
  36. "I cannot find the other tutorial files.  I have looked in the current" _n
  37. "directory and in \stata (DOS) or /usr/stata (Unix).  Is Stata installed" _n
  38. "correctly?" _n(2)
  39. "In any case, I cannot run the tutorial." ;
  40.             #delimit cr
  41.             exit
  42.         }
  43.     }
  44. }
  45. macro define F5 "do %path`contents.tut;"
  46. macro define F6 "do %path`tables.tut;"
  47. #delimit ;
  48.  
  49.  
  50. di in wh
  51. ". use %path`systolic, clear" ;
  52. noisily use %path`systolic, clear ;
  53. set more 0 ; more ; set more 1;
  54.  
  55.  
  56. di _n in wh _dup(79) "-" _n in gr
  57. "Below, we " in wh "describe" in gr " and " in wh "list"
  58. in gr " a small amount of our data:" _n
  59. in wh _dup(79) "-" _n(2)
  60. ". describe" ;
  61. noisily describe ;
  62.  
  63. di in wh _n "list in 1/7" ;
  64. noisily list in 1/7 ;
  65. set more 0 ; more ; set more 1 ;
  66.  
  67.  
  68. di _n(4) in wh _dup(79) "-" _n in gr
  69. "If you type" _n(2)
  70. _col(10) in wh "tabulate " in gr "variable-name" _n(2)
  71. "Stata produces a one-way tabulation of the variable:" _n
  72. in wh _dup(79) "-" _n(5)
  73. ". tabulate drug" ;
  74. di ;
  75. noisily tabulate drug ;
  76. di _n ;
  77. set more 0 ; more ; set more 1 ;
  78.  
  79. di _n(2) in wh _dup(79) "-" _n in gr
  80. "If you type" _n(2)
  81. _col(10) in wh "tabulate " in gr "variable-name variable-name" _n(2)
  82. "Stata produces a two-way tabulation:" _n
  83. in wh _dup(79) "-" _n(4)
  84. ". tabulate drug disease" ;
  85. noisily tabulate drug disease;
  86. di _n ; set more 0 ; more ; set more 1 ;
  87.  
  88. di _n(2) in wh _dup(79) "-" _n in gr
  89. "Stata can present a number of variations on the two-way table.  The entries"
  90. _n
  91. "in the table are controlled by options:" _n(2)
  92. _col(15) in wh "nofreq" _col(31) in gr "suppress reporting frequencies" _n
  93. _col(15) in wh "column" _col(31) in gr "report column percentages" _n
  94. _col(15) in wh "row" _col(31) in gr "report row percentages" _n
  95. _col(15) in wh "cell" _col(31) in gr "report cell percentages" _n ;
  96.  
  97. di in gr
  98. "On the next screen, we repeat the disease by drug table, reporting all the" _n
  99. "statistics.  Notice that we abbreviate the "
  100. in wh "tabulate" in gr " command, the " in wh "column" in gr " option," _n
  101. "and even the variable names!  Experienced Stata users seldom type out anything."
  102.  _n
  103. in wh _dup(79) "-" _n(10)
  104. ". tab dis dr, col row cell" ;
  105. set more 0 ; more ; set more 1 ;
  106. noisily tab dis dr, col row cell ;
  107. set more 0 ; more ; set more 1 ;
  108.  
  109. di _n(2) in wh _dup(79) "-" _n in gr
  110. "Stata can present solely the statistics you want in the table.  The table" _n
  111. "below reports the frequencies and the column percentages:" _n
  112. in wh _dup(79) "-" _n(3)
  113. ". tab disease drug, col" ;
  114. noisily tab disease drug, col ;
  115. set more 0 ; more ; set more 1 ;
  116.  
  117. di _n(6) in wh _dup(79) "-" _n in gr
  118. "Stata can calculate the chi-square statistic for the independence of the" _n
  119. "rows and columns if we specify the '"
  120. in wh "chi2" in gr "' option:" _n
  121. in wh _dup(79) "-" _n(6)
  122. ". tab disease drug, chi2" ;
  123. noisily tab disease drug, chi2 ;
  124. di _n ; set more 0 ; more ; set more 1 ;
  125.  
  126. di _n(2) in wh _dup(79) "-" _n in gr
  127. "Stata can make N-way tabulations, too.  If you want a three-way tabulation" _n
  128. "of var1 by var2 by var3, you type:" _n(2)
  129. in wh
  130. _col(16) "sort var1" _n
  131. _col(16) "by var1:  tabulate var2 var3" _n(2) in gr
  132. "Our data doesn't have a third categorical variable, so we won't illustrate" _n
  133. "this capability." _n
  134. in wh _dup(79) "-" _n(13) ;
  135. set more 0 ; more ; set more 1 ;
  136.  
  137. di _n in wh _dup(79) "-" _n in gr
  138. "Our data includes the change in the systolic blood pressure for each patient."
  139. _n
  140. "We can obtain summary statistics on the systolic variable, by drug, by typing:"
  141. _n
  142. in wh _dup(79) "-" _n(6)
  143. ". tabulate drug, summarize(systolic)" ;
  144. noisily tabulate drug, summarize(systolic) ;
  145. di _n(2) ; set more 0 ; more ; set more 1 ;
  146.  
  147. di _n in wh _dup(79) "-" _n in gr
  148. "Stata can perform two-way breakdowns, as well.  Just as we obtained the fre-"
  149. _n
  150. "quencies, we type '"
  151. in wh "tabulate" in gr "' followed by '"
  152. in wh "disease drug" in gr "', and then add the" _n
  153. "'" in wh "summarize(systolic)" in gr "' option:" _n
  154. in wh _dup(79) "-" _n(18)
  155. ". tab disease drug, sum(systolic)" ;
  156. set more 0 ; more ; set more 1 ;
  157. noisily tab disease drug, sum(systolic) ;
  158. di ; set more 0 ; more ; set more 1 ;
  159.  
  160. di _n in wh _dup(79) "-" _n in gr
  161. "Stata presented a table that reported the mean, standard deviation, and fre-"
  162. _n
  163. "quencies.  We can control exactly what the table reports using the '"
  164. in wh "mean" in gr "'," _n
  165. "'" in white "standard" in gr "', and '" in wh "freq" in gr "' options:" _n
  166. in wh _dup(79) "-" _n(4)
  167. ". tab disease drug, sum(systolic) mean" ;
  168. noisily tab disease drug, sum(systolic) mean ;
  169. di _n(2) ; set more 0 ; more ; set more 1 ;
  170.  
  171. di _n in wh _dup(79) "-" _n in gr
  172. "Stata can make N-way breakdowns of summary statistics, as well.  If you" _n
  173. "wanted to make a three-way table of the summary statistics on 'contvar' by" _n
  174. "'var1', 'var2', and 'var3', you type:" _n(2) in wh
  175. _col(16) "sort var1" _n
  176. _col(16) "by var1: tab var2 var3, sum(contvar)" _n(2) in gr
  177. "Our data doesn't have a third categorical variable, so we won't illustrate" _n
  178. "this capability." _n
  179. in wh _dup(79) "-" _n(13) ;
  180. set more 0 ; more ; set more 1 ;
  181.  
  182. drop _all ;
  183. label drop _all ;
  184.  
  185. di _n(4) in white
  186. "Demonstration ends" _n
  187. "------------------" _n ;
  188.  
  189. macro define F6 "do %path`regress.tut;" ;
  190.  
  191. di in green
  192. "That concludes our short demonstration, but there's much more.  We now return"
  193. _n
  194. "control to you.  Some suggestions:" _n ;
  195.  
  196. di in green
  197. "If you ..." _col(34) "Then we will show you ..." _n
  198. "    Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
  199. "    Press " in white "F6" in green _col(38) "the next tutorial, "
  200. in white "regress.tut" _n ;
  201.  
  202. run %path`tobuy.tut ;
  203.